/*
 * Copyright 2013 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.tieba.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fujitsu.nanjing.tieba.base.BaseController;
import com.fujitsu.nanjing.tieba.service.BoardBlobsInfoService;
import com.fujitsu.nanjing.tieba.service.TopicService;
import com.fujitsu.nanjing.tieba.service.UserService;
import com.fujitsu.nanjing.tieba.service.VisitStatService;

/**
 * StatController.java
 * 
 * @author Administrator
 */
@Controller
@RequestMapping("/forum/stat")
public class StatController extends BaseController {
	@Resource
	private VisitStatService visitStatService;
	@Resource
	private UserService userService;
	@Resource
	private TopicService topicService;
	@Resource
	private BoardBlobsInfoService boardBlobsInfoService;
	@RequestMapping(value = "/baseinfo", method = RequestMethod.GET)
	public String baseInfo(Model model) {
		model.addAttribute("statType", "baseinfo");
		return "/stat/baseinfo/baseinfo";
	}
	@RequestMapping(value = "/flux", method = RequestMethod.GET)
	public String flux(Model model) {
		model.addAttribute("visitStats", visitStatService.findVisitStats());
		model.addAttribute("statType", "flux");
		return "/stat/flux/flux";
	}
	@RequestMapping(value = "/topBoards", method = RequestMethod.GET)
	public String topBoards(Model model) {
		model.addAttribute("statType", "topBoards");
		model.addAttribute("topicBoards",
				boardBlobsInfoService.findBoardsWithOrder("topics"));
		model.addAttribute("replyBoards",
				boardBlobsInfoService.findBoardsWithOrder("replies"));
		return "/stat/topBoards/topBoards";
	}
	@RequestMapping(value = "/topTopics", method = RequestMethod.GET)
	public String topTopics(Model model) {
		model.addAttribute("visitsTopics", topicService.findTopVisitsTopics());
		model.addAttribute("repliesTopics", topicService.findTopRepliesTopics());
		model.addAttribute("statType", "topTopics");
		return "/stat/topTopics/topTopics";
	}
	@RequestMapping(value = "/topCreditsUsers", method = RequestMethod.GET)
	public String topCreditsUsers(Model model) {
		model.addAttribute("creditsUsers", userService.findTopCreditsUsers());
		model.addAttribute("postsUsers", userService.findTopPostsUsers());
		model.addAttribute("statType", "topCreditsUsers");
		return "/stat/topCreditsUsers/topCreditsUsers";
	}
	@RequestMapping(value = "/admins", method = RequestMethod.GET)
	public String admins(Model model) {
		model.addAttribute("admins", userService.findAdmins());
		model.addAttribute("statType", "admins");
		return "/stat/admins/admins";
	}
}
